/*
 * Created by SharpDevelop.
 * User: GZamor1
 * Date: 8/22/2007
 * Time: 4:13 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections.Generic;
using System.Collections;
using System.Xml;
using System.Text;

using MediaPortal.GUI.Library;
using MediaPortal.Configuration;

namespace OnlineVideos
{
	/// <summary>
	/// Description of GenericSiteUtil.
	/// </summary>
	public class GenericSiteUtil:SiteUtilBase
	{
		
			
		
		public override string getSiteId()
		{
			return "50";
		}

		protected override String getUrl(String fsId)
		{
			return fsId;
		}
		public override List<GUIOnlineVideos.VideoInfo> getVideoList(string fsUrl)
		{
			List<RssItem> loRssItemList = getRssDataItems(fsUrl);
			List<GUIOnlineVideos.VideoInfo> loVideoList = new List<GUIOnlineVideos.VideoInfo>();
			GUIOnlineVideos.VideoInfo video;
			foreach(RssItem rssItem in loRssItemList){
				video = new GUIOnlineVideos.VideoInfo();
				if(!String.IsNullOrEmpty(rssItem.description)){
					video.Description = rssItem.description;
				}else{
					video.Description = rssItem.mediaDescription;
				}
				if(!String.IsNullOrEmpty(rssItem.mediaThumbnail)){
					video.ImageUrl = rssItem.mediaThumbnail;
				}
				else if(!String.IsNullOrEmpty(rssItem.exInfoImage)){
					video.ImageUrl = rssItem.exInfoImage;
				}
				//get the video
				if(!String.IsNullOrEmpty(rssItem.enclosure)&& isPossibleVideo(rssItem.enclosure)){
					video.VideoUrl = rssItem.enclosure;
					video.Length = rssItem.enclosureDuration;
				}
				else if(rssItem.contentList.Count>0){
					foreach(MediaContent content in rssItem.contentList){
						if(isPossibleVideo(content.url)){
							video.VideoUrl = content.url;
							video.Length = content.duration;
							break;
						}
						
					}
					
					
				}
				//if(!String.IsNullOrEmpty()){
				
				//}
				//if(!String.IsNullOrEmpty()){
				
				//}
				
				
				video.Title = rssItem.title;
				
				if(String.IsNullOrEmpty(video.VideoUrl)==false){

					loVideoList.Add(video);
				}
			}
			return loVideoList;
		}
		
	}
}
